package cn.dsp.admin.service.impl;


import cn.dsp.admin.entity.lot.Space;
import cn.dsp.admin.mapper.lot.SpaceMapper;
import cn.dsp.admin.service.ISpaceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class SpaceServiceImpl implements ISpaceService {

    @Autowired
    private SpaceMapper spaceMapper;

    @Override
    public Integer getAllByLid(Integer lotId) {
        Integer data=spaceMapper.findAllById(lotId);
        return data;
    }

    @Override
    public Integer getByLid(Integer lotId) {
        Integer data=spaceMapper.findById(lotId);
        return data;
    }

    @Override
    public Space getBySid(Integer SpaceId) {
        Space data=spaceMapper.findBySid(SpaceId);
        return data;
    }

    @Override
    public void updateMore(Integer lotId, Integer count) {
        Space space=new Space();
        space.setLotId(lotId);
        space.setIsBorrowed(0);
        for (int i=1;i<=count;i++){
            space.setSpaceId(spaceMapper.findBigId(lotId)+i);
            spaceMapper.save(space);
        }
    }

    @Override
    public void updateLess(Integer lotId, Integer count) {
        for (int i=1;i<=count;i++){
            Integer spaceId=spaceMapper.findSpaceId(lotId);
            spaceMapper.deleteById(lotId,spaceId);
        }
    }


}
